package littlewhisker.components.gallery {

	import flash.display.Sprite;
	/**
	 * @author Philip
	 */
	public class CarouselGallery extends AbstractGallery {
	
		private var _galleryWidth:Number;
		private var _galleryHeight:Number;
		private var _currentItem:Number;
		private var _prevItem:Number;
		private var _nextItem:Number;
		private var _spearation:Number;
		private var offset:int = 0;
		
		public function get galleryWidth() : Number {
			return _galleryWidth;
		}
		
		public function set galleryWidth(galleryWidth : Number) : void {
			_galleryWidth = galleryWidth;
		}
		
		public function get galleryHeight() : Number {
			return _galleryHeight;
		}
		
		public function set galleryHeight(gallerHeight : Number) : void {
			_galleryHeight = gallerHeight;
		}
		
		public function get spearation() : Number {
			return _spearation;
		}
		
		public function set spearation(spearation : Number) : void {
			_spearation = spearation;
		}
		
		public function CarouselGallery(asset:Sprite, items:Array, carouselWidth:Number, carouselHeight:Number):void{
			this.asset = asset;
			this.items = items;
			this.galleryWidth = carouselWidth;
			this.galleryHeight = carouselHeight;
			spearation = (360/items.length);
			distribute();
			enabled = true;
		}
		
		private function distribute():void{
			for (var i : int = 0; i < items.length; i++) {
				var item:CarouselGalleryItem = items[i] as CarouselGalleryItem;
				item.galleryHeight = galleryHeight;
				item.galleryWidth = galleryWidth;
				item.separation = spearation;
				item.index = i;
				item.position = i;
				item.setToPosition();
				asset.addChild(item.asset);		
			}	
		}
		
		public function left():void{
			if(enabled){
				offset--;
				moveItems();
			}
		}
		
		public function right():void{
			if(enabled){
				offset++;
				moveItems();
			}
		}
		
		private function moveItems():void{
			for (var i : int = 0; i < items.length; i++) {
				var item:CarouselGalleryItem = items[i] as CarouselGalleryItem;
				item.position+offset;
				item.moveToPosition(spearation);
			}
		}
	}
}
